Skip to content
  • 0 Votes
    6 Posts
    725 Views
    BeaverShallBurnB

    @sierdzio, false alarm!

    After reopening my project everything got built and no file existance errors were present. Your hint about adding QCoreApplication really helped!

  • 1 Votes
    19 Posts
    11k Views
    JonBJ

    @Developer123
    The code answers there all implement sending Qt error messages within an application to a file. Perfectly useful in itself, but nothing to do with the topic title here of "How to redirect stdout & stderr to a file in a Qt console App (QCoreApplication)".

  • 0 Votes
    4 Posts
    1k Views
    Y

    For non Qt code I am trying to call Qcoreapplication with help of another thread.

    Here the code:
    ApplicationThread.h

    #pragma once #include <qthread.h> #include "squidstat_dll_global.h" #include <iostream> class SQUIDSTAT_DLLSHARED_EXPORT ApplicationThread:public QThread { void run(); }; class SQUIDSTAT_DLLSHARED_EXPORT ApplicationStarter : public QObject { Q_OBJECT public: ApplicationStarter(); ~ApplicationStarter(); public slots: void onStarted(); };

    ApplicationThread.cpp

    #include "ApplicationThread.h" #include "MainWindow.h" #include "qcoreapplication.h" namespace ToolThreadGlobal { static int argc = 1; static char* argv[] = { QString("SquidState.exe").toLocal8Bit().data(),NULL}; static QCoreApplication *coreApp = nullptr; static ApplicationThread *toolThread = nullptr; }; void ApplicationThread::run() { if (ToolThreadGlobal::coreApp){ std::cout << "\nApplicationThread: thread run method is call"; ToolThreadGlobal::coreApp->exec(); } } ApplicationStarter::ApplicationStarter() { if (ToolThreadGlobal::toolThread == nullptr) { std::cout << "\nApplicationstarter Constructor call"; ToolThreadGlobal::toolThread = new ApplicationThread(); connect(ToolThreadGlobal::toolThread, &ApplicationThread::started, this, &ApplicationStarter::onStarted, Qt::DirectConnection); ToolThreadGlobal::toolThread->start(); } } ApplicationStarter::~ApplicationStarter() { std::cout << "\nApplicationStarter:: destructor is called"; // Ensure that the thread and the QCoreApplication are cleanly shut down: ToolThreadGlobal::toolThread->quit(); ToolThreadGlobal::coreApp->quit(); ToolThreadGlobal::coreApp->deleteLater(); ToolThreadGlobal::coreApp = nullptr; ToolThreadGlobal::toolThread->terminate(); ToolThreadGlobal::toolThread->wait(); ToolThreadGlobal::toolThread->deleteLater(); ToolThreadGlobal::toolThread = nullptr; } void ApplicationStarter::onStarted() { std::cout << "\nApplicationStarter::signal received"; if (QCoreApplication::instance() == NULL) { std::cout << "\nApplicationStarter::call QcoreApplication"; ToolThreadGlobal::coreApp = new QCoreApplication(ToolThreadGlobal::argc, ToolThreadGlobal::argv); std::cout << "\nApplicationStarter::call worker"; MainWindow w; std::cout << "\nApplicationStarter::call before exe"; } }

    SquidState.h

    #pragma once #include "squidstat_dll_global.h" #include "ApplicationThread.h" #ifndef _SQUIDSTAT_H_ #define _SQUIDSTAT_H_ namespace AISquid { class SQUIDSTAT_DLLSHARED_EXPORT SquidStat { public: SquidStat(); ~SquidStat(); void startAPP(); void closeAPP(); }; } #endif // !_SQUIDSTAT_H_

    SquidState.cpp

    #include <stdlib.h> #include "SquidStat.h" #include "ApplicationThread.h" AISquid::SquidStat::SquidStat() { std::cout << "\nSquidStat: SquidStat class object is created"; }; AISquid::SquidStat::~SquidStat() { std::cout << "\nSquidStat: SquidStat class object is destriod "; }; void AISquid::SquidStat::startAPP() { }; void AISquid::SquidStat::closeAPP() { };

    Testing My dll with help of below code.

    tester.cpp

    #include "SquidStat.h" #include "ApplicationThread.h" void main(int argc, char *argv[]) { ApplicationStarter start; AISquid::SquidStat obj; obj.startAPP(); return; }

    OutPut of Tester:
    0_1554857416616_285cd514-f416-4d15-817b-51334702ce84-image.png

    What is wrong am I doing here? I am receiving call for slot onStarted(); once ApplicationStarter start; object is destroy.

    Any suggestion would be more appreciable.

  • 0 Votes
    3 Posts
    1k Views
    A

    @Johnx8664 Learning Qt4 at this point would be a waste of your time. Like @SGaist said it's long past it's end of life. Qt5 is 12 major releases into it's life cycle now and 5 years old now.

    I would grab a book on Qt5, or I find it's pretty easy to learn Qt just from the docs that come with it. If you know C++ well (and you should if you are tackling Qt), then you should be fine learning from the Qt Assistant docs. There are a lot of examples and tutorials in there as well.

  • 0 Votes
    4 Posts
    1k Views
    jsulmJ

    @newbieQTDev said in Use a QDialog box in Win32 Application:

    This is the version of my QT.

    No this is the Qt version which was used to build QtCreator (which is a Qt app).
    You're using Qt 5.6.0